<?php
// +----------------------------------------------------------------------
// | Author: sam
// +----------------------------------------------------------------------
namespace Sam;
use think\Db;

class Member {
	function __construct(){

    }
    public function get_id(){
		if( !isset($_COOKIE['znn_token']) || !$_COOKIE['znn_token'] ){
			return false;
		}
		$Account = Factory::createAccount();
		if( $id = $Account->decryptLoginToken($_COOKIE['znn_token']) ){
			return $id;
		}
		$Account->delLoginToken();
		return false;
	}

	/**
	 * 获取用户信息
	 */
	public function get_userinfo($id = 0){
		if( !$id ){
			$id = $this->get_id(); 
		}
		if( !$id ){
			return false;
		}

		$user = Db::name('member')
			->where('id', $id)
			->field('id,nickname,picture')
			->find();
		if( $user ){
			return $user;
		}else{
			return false;
		}
	}

}